/*
 * Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
  NOTE: This is the reference implementation, QtClient/ contains the real CnCNet client
*/

#include "common.h"
#include "launcher.h"

int main(int argc, char **argv)
{
    int ret;

    if(argc > 1)
    {
        ret = cncnet_launch(argv[1], NULL);
    }
    else if(FileExists("C&C95.exe"))
    {
        ret = cncnet_launch("C&C95.exe", "-LAN");
    }
    else if(FileExists("RA95.exe"))
    {
        ret = cncnet_launch("RA95.exe", "-LAN");
    }
    else if(FileExists("SUN.exe"))
    {
        ret = cncnet_launch("SUN.exe", NULL);
    }
    else if(FileExists("RA2.exe"))
    {
        ret = cncnet_launch("RA2.exe", NULL);
    }
    else if(FileExists("RA2MD.exe"))
    {
        ret = cncnet_launch("RA2MD.exe", NULL);
    }
    /* this last one is a fallback, TS, RA2 and RA2:YR should contain the launcher executable */
    else if(FileExists("GAME.exe"))
    {
        ret = cncnet_launch("GAME.exe", NULL);
    }
    else
    {
        printf("No game executables available.\n");
        return 1;
    }

    if(ret != CNCNET_ERROR_NO_ERROR)
    {
        printf("Launcher returned error code %02X\n", ret);
        return 1;
    }

#if _DEBUG
    printf("-- Press ENTER to close --\n");
    getchar();
#endif

    return 0;
}
